jQuery(function($) {
	
});
var queryInfo = function(){
	var data = $("#scoreQueryForm").serialize();
	$.ajax({
		type:"POST",
		url:ctx + "/admin/finance/scoreList",
		data:data,
		cache:false,
		success:function(data){
			$("#user-profile-1").html(data);
			$('[data-rel=tooltip]').tooltip();
		}
	});
}
var loadOwnDetail = function(){
	dataUrl = ctx + "/admin/finance/score/loadOwnDetail";
	if($('#scoreQueryForm input[name="userId"]').length > 0){
		$('#queryDetailForm input[name="userId"]').val($('#scoreQueryForm input[name="userId"]').val());
	}else{
		$('#queryDetailForm input[name="userId"]').val("");
	}
    $('#queryDetailForm input[name="agentId"]').val('');
	$('#queryDetailForm input[name="type"]').val(1);
	$('#queryDetailForm input[name="sd"]').val($('#scoreQueryForm input[name="sd"]').val());
	$('#queryDetailForm input[name="ed"]').val($('#scoreQueryForm input[name="ed"]').val());
	var data = $("#queryDetailForm").serialize();
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#"+contextId).html(data);
		}
	});
}
var loadPlayerDetail = function(){
	dataUrl = ctx + "/admin/finance/score/loadPlayerDetail";
	if($('#scoreQueryForm input[name="userId"]').length > 0){
		$('#queryDetailForm input[name="userId"]').val($('#scoreQueryForm input[name="userId"]').val());
	}
    $('#queryDetailForm input[name="agentId"]').val('');
	$('#queryDetailForm input[name="type"]').val(2);
	$('#queryDetailForm input[name="sd"]').val($('#scoreQueryForm input[name="sd"]').val());
	$('#queryDetailForm input[name="ed"]').val($('#scoreQueryForm input[name="ed"]').val());
	
	var data = $("#queryDetailForm").serialize();
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#"+contextId).html(data);
		}
	});
}
function loadPlayerData(agentId){
	parent.window.Index.addTab(ctx + "/admin/usermanager/myPlayer?agentId="+agentId
			+"&sd="+$('#scoreQueryForm input[name="sd"]').val()
			+"&ed="+$('#scoreQueryForm input[name="ed"]').val()
			,"【"+agentId+"】下属玩家");

}
var loadAgentDetail = function(orderBy){
	dataUrl = ctx + "/admin/finance/score/loadAgentDetail";
	if($('#scoreQueryForm input[name="userId"]').length > 0){
		$('#queryDetailForm input[name="userId"]').val($('#scoreQueryForm input[name="userId"]').val());
	}else{
		$('#queryDetailForm input[name="userId"]').val("");
	}
    $('#queryDetailForm input[name="agentId"]').val('');
	$('#queryDetailForm input[name="type"]').val(3);
	$('#queryDetailForm input[name="sd"]').val($('#scoreQueryForm input[name="sd"]').val());
	$('#queryDetailForm input[name="ed"]').val($('#scoreQueryForm input[name="ed"]').val());
	if(orderBy!=null){
        $('#queryDetailForm input[name="orderBy"]').val(orderBy);
	}

	var data = $("#queryDetailForm").serialize();
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#"+contextId).html(data);
		}
	});
}

var loadGoldDetail = function(orderBy){
    dataUrl = ctx + "/admin/finance/score/loadGoldDetail";
    if($('#scoreQueryForm input[name="userId"]').length > 0){
        $('#queryDetailForm input[name="userId"]').val($('#scoreQueryForm input[name="userId"]').val());
    }else{
        $('#queryDetailForm input[name="userId"]').val("");
    }
    $('#queryDetailForm input[name="agentId"]').val('');
    $('#queryDetailForm input[name="type"]').val(4);
    $('#queryDetailForm input[name="sd"]').val($('#scoreQueryForm input[name="sd"]').val());
    $('#queryDetailForm input[name="ed"]').val($('#scoreQueryForm input[name="ed"]').val());
    if(orderBy!=null){
        $('#queryDetailForm input[name="orderBy"]').val(orderBy);
    }

    var data = $("#queryDetailForm").serialize();
    $.ajax({
        type:"POST",
        url:dataUrl,
        data:data,
        cache:false,
        success:function(data){
            $("#"+contextId).html(data);
        }
    });
}

var nextAgent = function(agentId,orderBy){
	dataUrl = ctx + "/admin/finance/score/loadAgentDetail";
	$('#queryDetailForm input[name="userId"]').val('');
    $('#queryDetailForm input[name="agentId"]').val(agentId);
	$('#queryDetailForm input[name="type"]').val(3);
	$('#queryDetailForm input[name="sd"]').val($('#scoreQueryForm input[name="sd"]').val());
	$('#queryDetailForm input[name="ed"]').val($('#scoreQueryForm input[name="ed"]').val());
    if(orderBy!=null){
        $('#queryDetailForm input[name="orderBy"]').val(orderBy);
    }
	
	var data = $("#queryDetailForm").serialize();
	$.ajax({
		type:"POST",
		url:dataUrl,
		data:data,
		cache:false,
		success:function(data){
			$("#"+contextId).html(data);
		}
	});
}

var excel = function(){
	if(!queryDetailForm){
		return;
	}
	var form = $(queryDetailForm);
	form.attr("action", ctx+"/admin/excelExport/scoreExport");
	form.submit();
}

var agentOrderBy = function(orderBy){
	if($('#queryDetailForm input[name="type"]').val() == 3){
        if($('#scoreQueryForm input[name="agentId"]').length > 0){
            nextAgent($('#queryDetailForm input[name="agentId"]').val(), orderBy);
        }else{
            loadAgentDetail(orderBy);
		}
	}
}